package ph.com.gs3.formalistics.presenter;

import ph.com.gs3.formalistics.R;
import ph.com.gs3.formalistics.global.utilities.logging.FLLogger;
import ph.com.gs3.formalistics.model.rdao.TestFilesRDAO;
import ph.com.gs3.formalistics.model.vo.application.APIResponse;
import ph.com.gs3.formalistics.presenter.fragments.views.TesterViewFragment;
import retrofit.RestAdapter;
import android.app.Activity;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;

public class TesterActivity extends Activity {

	public static final String TAG = TesterActivity.class.getSimpleName();

	private TesterViewFragment viewFragment;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_tester);
		if (savedInstanceState == null) {
			viewFragment = new TesterViewFragment();
			getFragmentManager().beginTransaction().add(R.id.container, viewFragment).commit();
		}
		
		
		testTask.execute();
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.tester, menu);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		// Handle action bar item clicks here. The action bar will
		// automatically handle clicks on the Home/Up button, so long
		// as you specify a parent activity in AndroidManifest.xml.
		int id = item.getItemId();
		if (id == R.id.action_settings) {
			return true;
		}
		return super.onOptionsItemSelected(item);
	}

	private AsyncTask<Void, Void, Void> testTask = new AsyncTask<Void, Void, Void>() {

		@Override
		protected Void doInBackground(Void... params) {

			RestAdapter restAdapter = new RestAdapter.Builder().setEndpoint("http://192.168.0.57").build();

			TestFilesRDAO testFilesRDAO = restAdapter.create(TestFilesRDAO.class);
			APIResponse loginResponse = testFilesRDAO.login("ervinne.sodusta@gs3.com.ph", "password");
			APIResponse response = testFilesRDAO.getUser(26);
			
			FLLogger.e(TAG, "Login: " + loginResponse.getError());
			FLLogger.d(TAG, "Login: " + loginResponse.getResults());
			FLLogger.e(TAG, "Get User: " + response.getError());
			FLLogger.d(TAG, "Get User" + response.getResults());

			return null;
		}

		@Override
		protected void onPostExecute(Void result) {
			super.onPostExecute(result);
		}

	};

}
